package com.example.blood_sugar.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.blood_sugar.db.RecordDbSchema.RecordTable;

/**
 * 数据库操作helper
 */
public class RecordBaseHelper extends SQLiteOpenHelper {

    // 数据库版本
    private static final int VERSION = 1;
    // 数据库名字
    private static final String DATABASE_NAME = "bs_bp_hbalc_records.db";

    /**
     * 构造方法
     * @param context
     */
    public RecordBaseHelper(Context context){
        super(context, DATABASE_NAME, null, VERSION);
    }

    /**
     * 根据Schema（协议）创建数据库
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + RecordTable.NAME + "(" +
                " _id integer primary key autoincrement, " + // 主键
                RecordTable.Cloumns.DATE                    + ", " +
                RecordTable.Cloumns.DAWN                    + ", " +
                RecordTable.Cloumns.BEFORE_BREAKFAST        + ", " +
                RecordTable.Cloumns.AFTER_BREAKFAST         + ", " +
                RecordTable.Cloumns.BEFORE_LUNCH            + ", " +
                RecordTable.Cloumns.AFTER_LUNCH             + ", " +
                RecordTable.Cloumns.BEFORE_DINNER           + ", " +
                RecordTable.Cloumns.AFTER_DINNER            + ", " +
                RecordTable.Cloumns.BEFORE_SLEEP            + ", " +
                RecordTable.Cloumns.SYSTOLIC_BP             + ", " +
                RecordTable.Cloumns.DIASTOLIC_BP            + ", " +
                RecordTable.Cloumns.SACCHARIFICATION_VALUE  +
                ")"
        );
    }

    /**
     * 更新数据库
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
